package rmhc.gui
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.geom.Point;
	
	public class GridContainer extends MovieClip
	{
		protected var rowCount:uint;
		protected var cellWidth:Number, cellHeight:Number;
		protected var spaceX:Number, spaceY:Number;
		
		protected var curCol:int = 0 , curRow:int = 0;
		protected var cont:MovieClip;
		
		public function GridContainer( rowCount:uint = 1 , cellWidth:Number = 80 , cellHeight:Number = 50 , spaceX:Number = 6 , spaceY:Number = 10 )
		{
			super();
			this.rowCount = rowCount;
			this.cellWidth = cellWidth;
			this.cellHeight = cellHeight;
			this.spaceX = spaceX;
			this.spaceY = spaceY;
			
			cont = new MovieClip();
			addChild( cont );
		}
		
		public function addCell( o:DisplayObject ):void
		{
			var p:Point = getPosFor( curCol , curRow );
			cont.addChild( o );
			o.x = p.x;
			o.y = p.y;
			
			if ( curRow + 1 >= rowCount )
			{
				curRow = 0;
				curCol++;
			}
			else
			{
				curRow++;
			}
		}
		
		protected function getPosFor( col:int , row:int ):Point
		{
			var contw:Number = col * cellWidth;
			var spacew:Number = col * spaceX;
			
			var conth:Number = row * cellHeight;
			var spaceh:Number = row * spaceY;
			
			var p:Point = new Point();
			p.x = contw + spacew;
			p.y = conth + spaceh;
			
			return p;
		}
	}
}